package com.huige.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * ClassName: TimeAspect
 * Package: com.huige.pojo
 * Description:
 *
 * @Author 朱志辉
 * @Create 2024/5/7 19:55
 * @Version 1.0
 */
@Slf4j
@Component
//@Aspect//AOP类
public class TimeAspect {

//    @Around("execution(* com.huige.service.impl.DeptServiceImpl.*(..))")//切入点表达式
    @Around("com.huige.aop.MyAspect1.pt()")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        //1.记录开始时间
        long begin = System.currentTimeMillis();

        //2.调用原始方法运行
        Object proceed = pjp.proceed();

        //3.记录结束时间，计算方法执行耗时
        long end = System.currentTimeMillis();
        log.info(pjp.getSignature() + "方法执行耗时：{}ms", end - begin);

        return proceed;

    }
}